<template>
	<view class="page">
		<q-navbar title="首页" :isBack="false"></q-navbar>
		<view class="page_header">
			<q-tabs :list="tablist" bgColr="#27b8a6" textColor="#fff" :isScroll='true' activeColor="#fff"
				:barWidth='120' @change="(l,v)=>{
					requestParams.pageNum = 1,
					requestParams.typeId=v,
					getList(1)
				}" />
		</view>
		<view class="page_container">
			<listItem v-for="(v,i) in list" :key="i" :item="v"
				@Click="router.push({path:`/pages/index/detail/detail?id=${v.id}`,time:0})" />
		</view>
		<q-tabbar :current='0' />
	</view>
</template>

<script>
	import listItem from '@/pages/index/components/list-item.vue'
	export default {
		components: {
			listItem
		},
		props: {},
		data() {
			return {
				tablist: [{
					label: '全部',
					value: ''
				}],
				list: [],
				requestParams: {
					pageSize: 10,
					pageNum: 1,
				},
				total: 0,
				loading: false,
				status: 'loadmore',
			}
		},
		watch: {},
		// 必须要在onReady生命周期，因为onLoad生命周期组件可能尚未创建完毕
		onReady() {},
		onLoad(options) {
			this.findType()
		},
		onShow() {
			this.getList(1)
		},
		methods: {
			async findType() {
				let res = await this.$api.getTypeList('sys_call_article')
				console.log('号源类型', res);
				res.data.forEach(v => {
					v.label = v.dictLabel
					v.value = v.dictValue
				})
				this.tablist.push(...res.data)
			},
			getList(e) {
				this.loading = true
				this.$api.listArticle(this.requestParams).then(res => {
					this.status = 'loadmore'
					if (e) {
						this.list = res.rows
						this.total = res.total
					} else {
						this.list.push(...res.rows)
					}
					this.loading = false
					if (this.list.length >= this.total) {
						this.status = 'nomore'
					} else {
						this.status = 'loadmore'
					}
				})
			},
		},
		// 加载
		onReachBottom() {
			if (!this.loading) {
				if (this.list.length >= this.total) return
				this.status = 'loading'
				this.requestParams.pageNum += 1
				this.getList()
			}
		},
	}
</script>

<style lang="scss" scoped>
	.page {
		min-height: 100vh;
		width: 100vw;
		background-color: #eaeaea;
	}
</style>